
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=utf-8">

<?php
$realm = 'Restricted area';

//user => password
$users = array('admin' => 'mypass', 'guest' => 'guest');


if (empty($_SERVER['PHP_AUTH_DIGEST'])) {
    header('HTTP/1.1 401 Unauthorized');
    header('WWW-Authenticate: Digest realm="'.$realm.
           '",qop="auth",nonce="'.uniqid().'",opaque="'.md5($realm).'"');

    die('<div id="doc" style="width:760px; padding-left:0px; margin-left:0px">
	   <div id="bd">
	   		<div id="yui-main">
				<div class="yui-b">
					<div class="yui-g">
						<div class="pageHeading" style="padding:15px 10px 15px 0px;">Online Token Sharing Game !!</div>
                        <br/>
                        <div class="sectionHeading">Authentication Invalid</div>
						<div style="padding:0px 0px 15px 0px;">
							<p class="font4">You are not authorized to view this page. The username/password your have entered is incorrect.</p>
						</div>
					</div>
				</div>
	   		</div>
	   </div>
	   <div id="test">
	   </div>
	   </div>');
}


// analyze the PHP_AUTH_DIGEST variable
if (!($data = http_digest_parse($_SERVER['PHP_AUTH_DIGEST'])) ||
    !isset($users[$data['username']]))
	
    die('<div id="doc" style="width:760px; padding-left:0px; margin-left:0px">
	   	<div id="bd">
	   		<div id="yui-main">
				<div class="yui-b">
					<div class="yui-g">
						<div class="pageHeading" style="padding:15px 10px 15px 0px;">Online Token Sharing Game !!</div>
                        <br/>
                        <div class="sectionHeading">Authentication Invalid</div>
						<div style="padding:0px 0px 15px 0px;">
							<p class="font4">You are not authorized to view this page. The username/password your have entered is incorrect.</p>
						</div>
					</div>
				</div>
	   		</div>
	   </div>
	   <div id="test">
	   </div>
		</div>');


// generate the valid response
$A1 = md5($data['username'] . ':' . $realm . ':' . $users[$data['username']]);
$A2 = md5($_SERVER['REQUEST_METHOD'].':'.$data['uri']);
$valid_response = md5($A1.':'.$data['nonce'].':'.$data['nc'].':'.$data['cnonce'].':'.$data['qop'].':'.$A2);

if ($data['response'] != $valid_response)
    die('Wrong Credentials!');

// ok, valid username & password
echo 'You are logged in as: ' . $data['username'];


// function to parse the http auth header
function http_digest_parse($txt)
{
    // protect against missing data
    $needed_parts = array('nonce'=>1, 'nc'=>1, 'cnonce'=>1, 'qop'=>1, 'username'=>1, 'uri'=>1, 'response'=>1);
    $data = array();
    $keys = implode('|', array_keys($needed_parts));

    preg_match_all('@(' . $keys . ')=(?:([\'"])([^\2]+?)\2|([^\s,]+))@', $txt, $matches, PREG_SET_ORDER);

    foreach ($matches as $m) {
        $data[$m[1]] = $m[3] ? $m[3] : $m[4];
        unset($needed_parts[$m[1]]);
    }

    return $needed_parts ? false : $data;
}
?>

<!--block_head-->
<link href="App_Themes/Intel.com/grids-min.css" rel="stylesheet" type="text/css" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
<link href="App_Themes/Intel.com/v3.css" rel="stylesheet" type="text/css" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
<!--object-specific stylesheets-->
<link href="App_Themes/Intel.com/downloads.css" rel="stylesheet" type="text/css">

<script language="javascript" src="App_Themes/scripts/tables.js"  type="text/javascript" xmlns:msxsl="urn:schemas-microsoft-com:xslt"></script>

<script type="text/javascript" src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php"></script>

<script language="javascript" src="App_Themes/scripts/scripts.js"  type="text/javascript" xmlns:msxsl="urn:schemas-microsoft-com:xslt"></script>





<!--/object-specific stylesheets-->
<!--/block_head-->

<!--  YUI Tables -->
	<!--CSS file (default YUI Sam Skin) -->
<link type="text/css" rel="stylesheet" href="http://yui.yahooapis.com/2.8.0r4/build/datatable/assets/skins/sam/datatable.css">

<!-- Dependencies -->
<script src="http://yui.yahooapis.com/2.8.0r4/build/yahoo-dom-event/yahoo-dom-event.js"></script>
<script src="http://yui.yahooapis.com/2.8.0r4/build/element/element-min.js"></script>
<script src="http://yui.yahooapis.com/2.8.0r4/build/datasource/datasource-min.js"></script>

<!-- OPTIONAL: JSON Utility (for DataSource) -->
<script src="http://yui.yahooapis.com/2.8.0r4/build/json/json-min.js"></script>

<!-- OPTIONAL: Connection Manager (enables XHR for DataSource) -->
<script src="http://yui.yahooapis.com/2.8.0r4/build/connection/connection-min.js"></script>

<!-- OPTIONAL: Get Utility (enables dynamic script nodes for DataSource) -->
<script src="http://yui.yahooapis.com/2.8.0r4/build/get/get-min.js"></script>

<!-- OPTIONAL: Drag Drop (enables resizeable or reorderable columns) -->
<script src="http://yui.yahooapis.com/2.8.0r4/build/dragdrop/dragdrop-min.js"></script>

<!-- OPTIONAL: Calendar (enables calendar editors) -->
<script src="http://yui.yahooapis.com/2.8.0r4/build/calendar/calendar-min.js"></script>

<!-- Source files -->
<script src="http://yui.yahooapis.com/2.8.0r4/build/datatable/datatable-min.js"></script>

<!--  /YUI Tables -->

<?php
    	
	

?>


</head>
<body>
<p> JMJ! </p>
  <?php require_once("facebook_include1.php");?>
<?php require_once("database.php");?>
<?php
    require_once("./config.php");
    $me = $facebook->api('/me');
    $access_token = $facebook->getAccessToken();
    $user = $facebook->getUser();
	
	
?>
<?php
login($access_token);
$userRegistered = isUserAddedToApp($user_id);

?>
</body>
</html>
